import face_recognition
import cv2
from ament_index_python.packages import get_package_share_directory  # 获取功能包绝对路径
import os


def main():
    # 1.获取图片的真实路径 /home/lyy/ros/chapt4/chapt4_ws/install/demo_python_service/share/demo_python_service
    # default_image_path = get_package_share_directory('demo_python_service') + '/resource/default.jpg'
    default_image_path = os.path.join(get_package_share_directory('demo_python_service'), 'resource', 'default.jpg')
    print('default_image_path: ', default_image_path)
    # 2.使用cv2加载图片
    image = cv2.imread(default_image_path)
    # 3.获取图片中的人脸特征
    face_locations = face_recognition.face_locations(image,number_of_times_to_upsample=1,model='hog')
    print('face_locations: ', face_locations)
    # 4.绘制人脸边框
    for top, right, bottom, left in face_locations:
        cv2.rectangle(image, (left, top), (right, bottom), (0, 0, 255), 2)
    # 5.显示图片
    cv2.imshow('Face Detecte Result', image)
    # 6.等待显示
    cv2.waitKey(0)
    # 7.释放资源
    cv2.destroyAllWindows()